#include<malloc.h>
struct ListNode {
     int val;
     struct ListNode *next;
 };



struct ListNode* removeNthFromEnd(struct ListNode* head, int n){
    struct ListNode* fast=head;    
    struct ListNode* slow=head;
    struct ListNode*prev=(struct ListNode*)malloc(sizeof(struct ListNode));
    prev->val=0;
    prev->next=head;
    if(!head)return head;
    while(n--&&fast)
    {
        fast=fast->next;
    }
    while(fast)
    {
        fast=fast->next;
        slow=slow->next;
        prev=prev->next;
    }    
    prev->next=slow->next;
    return head;
}